package net.chenlin.dp.base.controller;

import net.chenlin.dp.base.entity.DictTableEntity;
import net.chenlin.dp.base.service.DictTableService;
import net.chenlin.dp.common.annotation.SysLog;
import net.chenlin.dp.common.entity.Page;
import net.chenlin.dp.common.entity.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * 字段字典表
 *
 * @author ZhouChenglin
 * @email yczclcn@163.com
 * @url www.chenlintech.com
 * @date 2018年2月02日 下午4:34:44
 */
@RestController
@RequestMapping("/dict/table")
public class DictTableController extends AbstractController {
	
	@Autowired
	private DictTableService dpTableColumService;
	
	/**
	 * 列表
	 * @param params
	 * @return
	 */
	@RequestMapping("/list")
	public Page<DictTableEntity> list(@RequestBody Map<String, Object> params) {
		return dpTableColumService.listDpTableColum(params);
	}
		
	/**
	 * 新增
	 * @param dpTableColum
	 * @return
	 */
	@SysLog("新增字段字典表")
	@RequestMapping("/save")
	public R save(@RequestBody DictTableEntity dpTableColum) {
		dpTableColum.setCreateTime(new Date());
		dpTableColum.setStatus(0);
		if(dpTableColum.getCodeType().equalsIgnoreCase("String")){
			dpTableColum.setcLength(255);
		}
		if(dpTableColum.getCodeType().equalsIgnoreCase("Integer")){
			dpTableColum.setcLength(11);
		}
		return dpTableColumService.saveDpTableColum(dpTableColum);
	}
	
	/**
	 * 根据id查询详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/info")
	public R getById(@RequestBody Long id) {
		return dpTableColumService.getDpTableColumById(id);
	}
	
	/**
	 * 修改
	 * @param dpTableColum
	 * @return
	 */
	@SysLog("修改字段字典表")
	@RequestMapping("/update")
	public R update(@RequestBody DictTableEntity dpTableColum) {
		return dpTableColumService.updateDpTableColum(dpTableColum);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	@SysLog("删除字段字典表")
	@RequestMapping("/remove")
	public R batchRemove(@RequestBody Long[] id) {
		return dpTableColumService.batchRemove(id);
	}



}
